package prictise.com.application1.transitionAnimation;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;
import java.util.Map;

import prictise.com.application1.BaseActivity;
import prictise.com.application1.R;
import prictise.com.application1.cusview.OverlayImageView;
import prictise.com.application1.utils.LogcatUtils;

public class TransitionAnimationActivity extends BaseActivity {
  private static final String TAG = "TransitionAnimationActivity";

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transition_animation);
//    final ImageView iv = findViewById(R.id.iv_1);
    final OverlayImageView iv = findViewById(R.id.o_iv_1);
    final ImageView iv1 = findViewById(R.id.iv_1);
    final ImageView iv2 = findViewById(R.id.iv_2);


    if((iv1.getDrawable().getCurrent().getConstantState())
            .equals(ContextCompat.getDrawable(this,R.mipmap.i1).getConstantState()))
    {
      //是图片a
      LogcatUtils.showDLog(TAG, "是图片a");
    } else {
      //不是
      LogcatUtils.showDLog(TAG, "不是图片a");
    }

    Drawable.ConstantState buttonConstantState = iv1.getDrawable()
            .getConstantState();
    Drawable.ConstantState resourceConstantState = getResources().getDrawable(
            R.mipmap.ic_launcher).getConstantState();
    boolean isEqual = buttonConstantState.equals(resourceConstantState);
    LogcatUtils.showDLog(TAG, "isEqual = " + isEqual);

    iv1.setDrawingCacheEnabled(true);
    // 获取ImageView中的图像
    Bitmap bt1 = iv1.getDrawingCache();
//    Bitmap sbmp = Bitmap.createBitmap(iv1.getDrawingCache());
    // 从ImaggeView对象(iv_photo)中获取图像后，要记得调用setDrawingCacheEnabled(false)
    // 清空画图缓冲区
    iv1.setDrawingCacheEnabled(false);

    iv2.setDrawingCacheEnabled(true);
    // 获取ImageView中的图像
    Bitmap bt2 = iv1.getDrawingCache();
    // 从ImaggeView对象(iv_photo)中获取图像后，要记得调用setDrawingCacheEnabled(false)
    // 清空画图缓冲区
    iv2.setDrawingCacheEnabled(false);

    LogcatUtils.showDLog(TAG, "bt1 = bt2 is " + (bt1 == bt2));

    Glide.with(this)
            .load("https://alifei05.cfp.cn/creative/vcg/800/new/VCG211323585460.jpg")
            .apply(new RequestOptions().placeholder(R.drawable.ic_launcher_background)
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE))
            .into(iv);

    final Intent intent = new Intent(this,TransitionAnimationActivity2.class);

    iv.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {

        ActivityOptionsCompat optionsCompat =
                ActivityOptionsCompat.makeSceneTransitionAnimation(TransitionAnimationActivity.this, iv, "image");
        startActivity(intent,optionsCompat.toBundle());

//        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
//                TransitionAnimationActivity.this, iv, "image");
//        ActivityCompat.startActivityForResult(TransitionAnimationActivity.this,
//                intent, 100, options.toBundle());

      }
    });
  }
}
